//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"

// 区间运算符可以用来表示两个操作数之间的范围集合。

// MARK : - // 1 闭区间运算符 : a...b

for iCount in 1...10 {
    print(iCount)
}

// MARK : - // 2 半闭区间运算符 : a..<b

var f = ["app","ori","ban"]
let iCount1 = f.count
for i in 0..<iCount1 {
    print(i)
}

// MARK : - // 3 倒序循环
// 通过 reversed() 方法, 我们可以将一个正序循环变成逆序循环.

for i in (0..<10).reversed() {
    print(i)
}

// MARK : - // 4 字符串范围也可以使用区间运算符
// 字符串截取
let word = "YxiangGeGe"

// 不使用区间运算符
let index = word.index(word.startIndex, offsetBy: 4)
let index2 = word.index(word.startIndex, offsetBy: 7)
let range1 = Range(uncheckedBounds: (lower: index, upper: index2))
let rangeStr1 = word.substring(with: range1)
print(rangeStr1)

// 使用区间运算符
let range2 = word.index(word.startIndex, offsetBy: 4)..<word.index(word.startIndex, offsetBy: 7)

let rangeStr2 = word.substring(with: range2)

print(rangeStr2)

// MARK : - // 5 区间运算符除了返回一个Range外, 还可以接受Comparable输入, 返回ClosedInterval或HalfOpenInterval  所以我们可以用这个特性检查字符串里的字符是不是都是合法字符（比如是不是都是小写）

let words = "Yxiang"
let interval = "a"..."z"
for c in words.characters {
    if !interval.contains(String(c)) {
        print("\(c)不是小写字母")
    }
}




